package com.lv.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lv.entity.Student;
import com.lv.entity.StudentREQ;
import com.lv.mapper.StudentMapper;
import com.lv.service.IStudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 我的代码-www.lv.com
 * @since 2021-06-30
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements IStudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public List<Student> findStudentScore() {

        return studentMapper.findStudentScore();
    }

    @Override
    public List<Student> findAll() {
        return studentMapper.selectList(null);
    }

    @Override
    public Student byname(String name, String gender) {
        return studentMapper.byname(name,gender);
    }

    @Override
    public List<Student> findByIds(List<Integer> ids) {
        return studentMapper.findByIds(ids);
    }

    public Page<Student> fenye(StudentREQ req){
        Page<Student> page = new Page<>(req.getCurrent(),req.getSize());

        QueryWrapper<Student> wrapper = new QueryWrapper();
        if(req.getName() != null && req.getName() != ""){
            wrapper.like("name", req.getName());
        }

        return studentMapper.selectPage(page, wrapper);
    }
}
